import api from '../../../api/apis'
import router from 'router'
export default {
    namespaced: true,
    state: {
        pages: 0,
        total: 10,
        pagesize: 3,
        startpage: 1,
        list:[],
        details:[],
    },
    mutations: {
        setStartpageData(state,newData){
            state.pages=newData.pages
            state.total=newData.total
            state.list=newData.list
        },
        searchData(state,newData){
            state.list=newData.list
            
        },
        setGetDataById(state,newData){
            // 
            state.details=[newData]
            console.log(state.details);
            // console.log(state.details[0].totalorderPrice);
        },
        setCurrentPage(state,newData){
            state.startpage = newData;
        },
        setPageSize(state,newData){
            state.pagesize = newData;
        },
    },
    actions: {
         async getpaging(context) {
            const data = await api.order.getpaging({
                pagesize:context.state.pagesize,
                startpage:context.state.startpage
            })
            console.log(data);
            if(data.data.code==200){
                context.commit('setStartpageData',data.data.object)
            }
        },
        async getDataById(context,id){
            const data = await api.order.getDataById({id:id})
            if(data.data.code==200){
                
                context.commit('setGetDataById',data.data.object)
            }
        },
        async search(context,nfuhTotalorderDto){
            const data = await api.order.search(nfuhTotalorderDto)
            console.log(data);
            if(data.data.code==200){
                context.commit('searchData',data.data.object)
            }
        },
        async settlement(context,newData){
            const data = await api.order.settlement({id:newData})
            console.log(data);
            // if(data.data.code==200){
            //     context.commit('searchData',data.data.object)
            // }
        },


    }
}